package websocketgulu.demo.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import websocketgulu.demo.common.lang.Result;
import websocketgulu.demo.service.DoctorService;
import websocketgulu.demo.service.PatientService;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 苏成
 * @Date: 2021/11/11/16:01
 * @Description:
 */

@RestController
public class LoginController {

    @Autowired
    DoctorService doctorService;

    @Autowired
    PatientService patientService;

    @PostMapping("/login")
    public Result login(@RequestParam Map<String, String> map){
        boolean result;
        System.out.println(map);
        Integer identity = Integer.valueOf( map.get( "identity" ) );
        if( identity == 0)
            result = patientService.login((HashMap) map);
        else
            result = doctorService.login((HashMap) map);
        System.out.println(result);
        if (result) {
            return Result.success("登录成功");
        } else {
            return Result.fail("登录失败");
        }
    }
}
